<?php
namespace api\xcx\controller;
use think\Cache;
use think\Loader;
use think\Db;
use think\Request;
use think\Controller;
use think\config;

/**
 *  Base.php 基础控制器
 *
 * @copyright			(C) 2014-2018 ShengTeng
 * @lastmodify			2018-06-21
 */
class Base extends Controller
{
    public function _initialize(){
        parent::_initialize();
        error_reporting(E_ERROR | E_PARSE );
    }

    /**
     * 根据token
     */
    public function getUserId($token){
        // 1.根据token获取用户id
        $user = Model('User');
        $userInfo = $user->getId($token);
        if(!$userInfo){
            exit(json_encode(returnAjax('','用户不存在','10')));
        }
        return $userInfo['userId'];
    }

    /**
     * 检测参数是否存在
     */
    public function checkParam($field,$name,$isNull){
        if(!isset($field)){
            exit(json_encode(returnAjax('','缺少参数'.$name,'1')));
        }else{
            if($isNull){
                if($name==""){
                    exit(json_encode(returnAjax('','参数'.$name.'不可为空','1')));
                }
            }
        }
        return $field;
    }

    /**
     * 查看员工是否存在
     * @param $token 员工token
     * @return $data\false
     */
    public function selStaff($token){
        $res = false;
        $staff = Model('Staff');
        $data = $staff->selByToken($token);
        if($data){
            $res = $data;
        }else{
            exit(json_encode(returnAjax('','员工不存在','10')));
        }        
        return $res;
    }
    
    /**
     * 查看店铺是否存在
     */
    public function selShop($shopId){
        $res = false;
        $shop = Model('Shop');
        $data = $shop->selById($shopId);
        if($data){
            $res = $data;
        }else{
            exit(json_encode(returnAjax('','店铺不存在','1')));
        }       
        return $res;
    }

    /**
     * 查看订单是否存在
     */
    public function selOrder($orderNumber){
        $res = false;
        $order = Model('Order');
        $data = $order->order_info($orderNumber);
        if($data){
            $res = $data;
        }else{
            exit(json_encode(returnAjax('','订单不存在','1')));
        }       
        return $res;
    }
}
